#!/bin/sh
### 添加了变量；if 函数
###

# 安装mysql

yum install -y mariadb

if [ $? -ne 0 ];then
 echo "yum install mariadb failed"
 exit 1
fi

url = http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
###2 install mariadb5.7
wget $url

if [ $? -ne 0 ]; then
 echo "wget is not installed"
 yum install -y wget
 wget $url
 if [ $? -ne 0 ]; then
  echo "download mariadb failed"
  exit 1
 fi 

fi

###3 install mariadb
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
if [ $? -ne 0 ]; then
 echo "rpm mysql failed"
 exit 1
fi


###4 install mysql-devel
yum -y install mysql-devel
if [ $? -ne 0 ]; then
 echo "rpm mysql failed"
 exit 1
fi

###5 set character-set in /etc/my.cnf
if [ ! -f "/etc/my.cnf" ]; then
 echo "/etc/my.cnf doesn't exists. set character-set failed."
 exit 1
fi


###6 这步骤有待优化
echo "[mysql]">> /etc/my.cnf
echo "default-character-set=utf8">> /etc/my.cnf

###7 重启
systemctl restart mysqld

# 如果文件不存在
if [ ! -f "/etc/my.cnf" ]; then
 echo "restart failed."
 exit 1
fi
